package cn.wtg.kotlinlib.singleActivityMulFragmentVM

import cn.wtg.kotlinlib.baseUi.BaseActivity
import cn.wtg.kotlinlib.baseUi.BaseFragment
import cn.wtg.kotlinlib.baseViewModel.BaseFragmentLifecycleVM
import cn.wtg.kotlinlib.utils.FragmentHelper

/**
 * author: wtg
 * date:2020/3/13 0013
 * desc: ViewModel的基类 fragment(单activity+多fragment)
 */
abstract class BaseFragmentBackStackLifecycleVM : BaseFragmentLifecycleVM {
    constructor(fragment: BaseFragment?) : super(fragment)
    constructor(fragment: BaseFragment?, mActivity: BaseActivity?) : super(fragment, mActivity)

    protected fun replaceFragment(baseBackStackFragment: BaseFragment) {
        if (mFragment != null && mFragment!!.activity == null) {
            return
        }
        FragmentHelper.replaceBackStackFragment(
            mFragment?.activity?.supportFragmentManager,
            baseBackStackFragment,
            baseBackStackFragment.TAG,
            getContainerId()
        )
    }

    /**
     * 获取布局容器id
     * @return id
     */
    abstract fun getContainerId(): Int
}